/**
  data-schema.h - Created by Timothy Morey on 5/22/2012.

  A data grid represents an n-dimensioned grid of data values.
*/

#ifndef __DATA_GRID_H
#define __DATA_GRID_H

#include <libxml/tree.h>

#include "libnvn.h"
#include "variant.h"

#define MAX_DIMS 3
#define MAX_VARS 32

typedef struct
{
  char Name[32];
  size_t Length;
  int IsUnlimited;
} DimensionSchema;

typedef struct
{
  char Name[32];
  int NDims;
  DimensionSchema Dims[MAX_DIMS];
  int DataType;
  Variant FillValue;
} DataGridSchema;

typedef struct
{
  char Name[32];
  int NVars;
  DataGridSchema Variables[MAX_VARS];
} DataSetSchema;

EXPORT int BuildDataGridSchema(const char* dataset, const char* varname, DataGridSchema* schema);

EXPORT int BuildDataSetSchema(const char* dataset, DataSetSchema* schema);

EXPORT int GetDimensionIndex(DataGridSchema schema, const char* dimname);

EXPORT int GetIndex(DataGridSchema schema, int* indices, int nindices);

EXPORT int GetLength(DataGridSchema schema);

EXPORT int GetLengthInBytes(DataGridSchema schema);

EXPORT int GetSliceLength(DataGridSchema schema);

EXPORT int GetSliceLengthInBytes(DataGridSchema schema);

EXPORT int ParseDataGridSchema(xmlNodePtr root, DataGridSchema* schema);

EXPORT int ParseDataSetSchema(xmlNodePtr root, DataSetSchema* schema);

EXPORT int ParseDimensionSchema(xmlNodePtr root, DimensionSchema* schema);

EXPORT int SaveDataGridSchema(DataGridSchema schema, xmlNodePtr* root);

EXPORT int SaveDataSetSchema(DataSetSchema schema, xmlNodePtr* root);

EXPORT int SaveDimensionSchema(DimensionSchema schema, int order, xmlNodePtr* root);

#endif